package com.bistu.openlab.uofspreadsheet.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/*
 *@author xiaoguang.gao@oracle.com
 *@version 2013-5-8 
 */
public class TypeConvertor {
	static DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
	/**
	 * 
	 * @param str
	 * @return
	 */
	public static Date GetDate(String str){
		str = str.replace('T', ' ');
		Date date = new Date();
		
		try {
			date = format.parse(str); 
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return date;
	}
	/**
	 * 
	 * @param date
	 * @return
	 */
	public static String GetString(Date date){
		String str = format.format(date); 
		str = str.replace(' ', 'T');
		return str;
	}
	/**
	 * 
	 * @param str
	 * @return
	 */
	public static int GetInt(String str){
		int ret = 0;
		try{
			ret = Integer.parseInt(str);
		}catch(NumberFormatException nfe){
			nfe.printStackTrace();
		}
		return ret;
	}
	public static double GetDouble(String str){
		double ret = 0.0;
		try{
			ret = Double.parseDouble(str);
		}catch(NumberFormatException nfe){
			nfe.printStackTrace();
		}
		return ret;
	}
}
